package com.itcast;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

public class StudentServletContext extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        ServletContext context = super.getServletContext();

        String globalencoding = context.getInitParameter("globalencoding");
        System.out.println(globalencoding);

        Enumeration<String> names = context.getInitParameterNames();
        while (names.hasMoreElements()) {
            String key = names.nextElement();
            String value = context.getInitParameter(key);
            System.out.println(key+","+value);
        }

        context.setAttribute("username","zhangsan");
        context.setAttribute("password", "1111");
        context.removeAttribute("password");

        String contextPath = context.getContextPath();
        System.out.println(contextPath);

        String a = context.getRealPath("/a.txt");
        System.out.println(a);

        String b = context.getRealPath("/WEB-INF/b.txt");
        System.out.println(b);

        String c = context.getRealPath("/WEB-INF/classes/c.txt");
        System.out.println(c);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }

}
